The next topic is outbound
traffic filtering, for when you want to prevent outbound
connections to unknown or dangerous hosts. To understand how that works. Let's first discuss Serverless VPC Access,
but before I can explain what
a Serverless VPC Access connector is. You'll need to know what the virtual
private cloud is or VPC. The VPC provides networking and
load balancing to resources in the VPC, examples of those resources include your
compute engine virtual machine instances, Google Kubernetes Engine containers. And other Google Cloud products
built on compute engine VMs, such as cloud SQL and memory store. As a heuristic, everything that can have
an internal IP address is part of the VPC, Cloud Run containers
are not part of the VPC. By default,
from a cloud run container, you can't connect with private resources that only
have an internal IP address in the VPC. This limitation comes as
surprise to many developers, but the solution is straightforward. You can create a VPC access connector
to access internal IP addresses. A VPC access connector is a resource
in the VPC that acts as a router to forward traffic from cloud run services. To use the connector, you'll need to configure your
cloud run service to use it. Note that you can only attach
one connector to each service. The VPC access connector
is not serverless. You can think of it as a group of virtual
machines that are always running. This means that you are charged for having
a connector enabled, even if it does not forward connections or even if it is
not attached to a cloud run service. If you attach a VPC access connector to a
cloud run service, you can send traffic to internal IP addresses as well as external
IP addresses on the public internet. The source IP for internal traffic is
an address from the VPC connector range, which means you can use the VPC security
controls like firewalls to monitor and control that traffic. The source IP for traffic to external IPs
is from the dynamic public address pool, which you share with all cloud run
services and also from other customers. This traffic is outside of your control, to control outbound
traffic from your service. You can set the VPC egress setting and route all traffic through
the VPC connector. If you enable this, all outbound
connections from the service are routed to your VPC network,
even if they have an external destination. The connections will adhere to the
network's firewall DNS and routing rules. This mode is useful for example, to
prevent outbound traffic too dangerous or unwanted hosts with your
network's firewall rules. Or to use a static outbound IP address
instead of one from the public pool with cloud network address translation. You can combine ingress and egress
settings to allow cloud run services to only communicate with each other. In order to do this,
set the ingress settings to internal only. This only allows traffic from
resources running in the VPC, and by default, it will disallow requests
from other cloud run services as they use an external IP address
from the public address pool. However, the Serverless VPC Access
connector is in fact a resource in the VPC. If you can figure a cloud run service to
route all outbound traffic through the VPC access connector. That service is able to send requests to
cloud run service that only allow requests from internal sources. Cloud run containers use a dynamic IP from
the public pool for outbound TCP slash IP. Use a serverless VPC access connector if
you want to connect with internal IPs in the VPC, while all traffic through
the Serverless VPC Access connector. If you want to prevent outbound traffic
too dangerous or unwanted hosts with your network's firewall rules or
use a static outbound IP address.